//
//  PCMeGameCell.m
//  PhotoCircle
//
//  Created by GL on 15/12/13.
//  Copyright © 2015年 wujungao. All rights reserved.
//

#import "PCMeGameCell.h"
#import "UIImageView+WebCache.h"

@interface PCMeGameCell ()

@property (weak, nonatomic) IBOutlet UIImageView *gameImageView;
@property (weak, nonatomic) IBOutlet UILabel *datelabel;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *markLabel;
@property (weak, nonatomic) IBOutlet UIButton *rightButton;
@property (weak, nonatomic) IBOutlet UIButton *leftButton;

@property (nonatomic, strong) PCUserGameModel *uGameModel;

@end

@implementation PCMeGameCell

- (void)awakeFromNib {
    // Initialization code
    
    _rightButton.layer.cornerRadius = _rightButton.frame.size.height/2.0;
    _rightButton.layer.masksToBounds = YES;
    //设置边框及边框颜色
    _rightButton.layer.borderWidth = 1.0;
    _rightButton.layer.borderColor =[[UIColor orangeColor] CGColor];
    
    _leftButton.layer.cornerRadius = _leftButton.frame.size.height/2.0;
    _leftButton.layer.masksToBounds = YES;
    //设置边框及边框颜色
    _leftButton.layer.borderWidth = 1.0;
    _leftButton.layer.borderColor =[[UIColor lightGrayColor] CGColor];
    
}

-(void)configCellWithModel:(PCUserGameModel *)gModel
{
    _rightButton.hidden = YES;
    _leftButton.hidden  = YES;
    
    self.uGameModel = gModel;
    NSURL *imgUrl  = [NSURL URLWithString:gModel.gImgUrl];
    [_gameImageView sd_setImageWithURL:imgUrl];
    _datelabel.text = gModel.gDate;
    _titleLabel.text = gModel.gTitle;
    _markLabel.text  = gModel.gMarkGame;
    
    [self configGameStates:self.uGameModel];
}

-(void)configGameStates:(PCUserGameModel *)gModel
{
    if ([gModel.gState isEqual:@"main_create"]) {
        
        _rightButton.hidden = NO;
        _leftButton.hidden  = NO;
        [_rightButton setTitle:@"待支付" forState:UIControlStateNormal];
        [_leftButton  setTitle:@"放弃参赛" forState:UIControlStateNormal];
        
    }else{
        _rightButton.hidden = YES;
        _leftButton.hidden  = YES;
    }
}

- (IBAction)rightButtonEvent:(UIButton *)sender {
    NSLog(@"rightButtonEvent");
    if ([self.delegate respondsToSelector:@selector(selectedRightButton:)]) {
        [self.delegate selectedRightButton:self.uGameModel];
    }
}

- (IBAction)leftButtonEvent:(id)sender {
    NSLog(@"leftButtonEvent");
    if ([self.delegate respondsToSelector:@selector(selectedLeftButton:)]) {
        [self.delegate selectedLeftButton:self.uGameModel];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
